package com.example.lunch;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StreamOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName AppLunch
 * @Description
 * @Author Jingxiao.Ye
 * @Date 2022/1/20 上午1:09
 * @Version V1.0
 * @Since JDK 11
 */
@Component
public class AppLunch implements ApplicationRunner {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    public void doOrderHandle(){
        StreamOperations<String, Object, Object> streamOperations = redisTemplate.opsForStream();
        streamOperations.createGroup("app_order_a","order_a");
        Map<String,Object> map = new HashMap<>();
        map.put("id",123);
        map.put("name","订单A");
        streamOperations.add("app_order_a",map);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        doOrderHandle();
    }
}
